package com.dinnerwithfriends.client.dinner.invite;

import com.dinnerwithfriends.client.authentication.facebook.FacebookFriends;
import com.dinnerwithfriends.client.authentication.facebook.FacebookImage;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.SuggestOracle.Suggestion;

/**
 * 
 * @UserInterface
 */
public class FriendsList {

	public static MultiWordSuggestOracle multiWordSuggestOracle = new MultiWordSuggestOracle();

	public FriendsList() {

		final SuggestBox suggestBox = new SuggestBox(multiWordSuggestOracle);
		suggestBox.addSelectionHandler(new SelectionHandler<Suggestion>() {

			@Override
			public void onSelection(SelectionEvent<Suggestion> event) {

				String name = event.getSelectedItem().getReplacementString();

				String friendID = FacebookFriends.facebookFriendsID.get(name);

				FriendsPanel.hpSelectedFriends.add(new FacebookImage(friendID,
						name));

				CreateDinner.selectedFriends.add(event.getSelectedItem()
						.getReplacementString());

				suggestBox.setValue(null);
			}
		});

		FriendsPanel.friendsPanel.clear();
		FriendsPanel.friendsPanel.add(suggestBox);

	}
}
